 @extends('template/master')	
	@section('pageTitle')
		{{ Lang::get('label.homePageTitle')}}
	@stop
	
	@section('content')
	<style>
		#resultst ol{margin: 0px;padding: 0px;}
		
	</style>
	 <!-- Page Content -->
    <div class="container">
		
		<ol class="breadcrumb">
		  	<li><a href="/">Home</a></li>
			<li>Search</li>
		</ol>
				
				
		<h1 class="title">search</h1>
		
		
		<form action="/{{Config::get('app.locale')}}/search" method="get">
			
			<div class="col-xs-9 col-lg-9 search-padding">
				<input value="<?php  if(isset($_GET['keyword'])){ echo $_GET['keyword'];}?>" name="keyword" type="search" class="form-control" placeholder="What are you looking for?">
			</div>
			<div class="col-xs-3 col-lg-3 search-padding">
			 	<button type="submit" class="btn btn-primary">SEARCH</button>
			</div>

		</form>
		

		
        <div class="clearfix"></div>
		
		
		 <!-- search by category-->
					<?php 
					if(isset($_GET['keyword'])){
                        $key = $_GET['keyword'];
                   }else{
                   		$key="";
                   }
                   if(isset($_GET['catId'])){
                        $catId = $_GET['catId'];
                   }else{
                   		$catId =0;
                   }
					?>
				<ul id="filters" class="list-inline">
						<li><strong>Filter by</strong></li>
 					 	<li><a href="/{{Config::get('app.locale')}}/search?keyword={{$key}}" data-filter="*">All</a></li>
			 					  <?php if( !empty($catList[0]) ) : ?>	
				       <?php foreach( $catList as $value ) : ?>      
						<li> <a href="/{{Config::get('app.locale')}}/search?keyword={{$key}}&catId={{$value['id']}}"><?php echo $value['name']; ?></a></li>
				       <?php endforeach; ?>    
				       <?php endif;?>
				
				</ul>
	
	   
	    <div class="row">

				

		    <!-- column7 -->
            <div class="col-md-7">

					<h4 class="title4">You have searched for <?php if($_GET['keyword']){ echo $_GET['keyword'];}?></h4>									
					<div id="news-filtering">					
						<div id="results">
						</div>
						<div class="animation_image" style="display:none" align="center"><img src="../images/ajax-loader.gif"></div>
								
					</div><!-- / news-filtering-->

            </div><!-- / column7-->

            <!-- Sidebar -->
            <div class="col-md-5">

        	<div class="clearfix"></div>

               <h1 class="title"><?php echo Lang::get('label.mostViewed'); ?></h1>
                    <div class="row">
                        <div class="col-lg-12">
                            <ul class="list-styled">
                                 <?php                                  
                                 foreach( $mostViewed as $value ) : $linkTo = SEO::generateNewsURL($value->id,$value->title); ?>
                            		<li><a href="{{ $linkTo }}" class="news-style"><?= $value->title;?></a></li>
                            	<?php endforeach; ?>                        
                            </ul>
                        </div>
                        <!-- /.col-lg-6 -->
                        
                    </div>
                    <!-- /.row -->
 				<h1 class="title"><?php echo Lang::get('label.mostCommented'); ?></h1>
                    <div class="row">
                        <div class="col-lg-12">
                            <ul class="list-styled">
                                 <?php foreach( $mostCommented as $value ) : $linkTo = SEO::generateNewsURL($value->id,$value->title); ?>
                            	<li><a href="{{ $linkTo }}" class="news-style"><?= $value->title;?></a></li>
                            	<?php endforeach; ?>								
                            </ul>
                        </div>
                        <!-- /.col-lg-6 -->
                        
                    </div>
                    <!-- /.row -->

            </div>  <!-- /.col-md-5-->
        </div> <!-- /.row -->
    </div> 
	<!-- /.container -->
	
	<?php  $total_page = ceil($countItem/5);
		$lang = Config::get('app.locale');	
	?>
	
	<script type="text/javascript">
$(document).ready(function() {
	var track_load = 0; //total loaded record group(s)
	var loading  = false; //to prevents multipal ajax loads
	var total_page =<?php echo $total_page; ?>; //total record group(s)
	var key = '<?php echo $key;?>';
	var cat_id =<?php echo $catId;?>;
	var lag = '<?php echo $lang;?>';
	$('#results').load("/searchdata", {'page_number':track_load,'key':key,'cat_id':cat_id,'lag':lag}, function() {track_load++;}); //load first group
	
	$(window).scroll(function() { //detect page scroll
		
		if($(window).scrollTop() + $(window).height() == $(document).height())  //user scrolled to bottom of the page?
		{
			
			if(track_load <= total_page && loading==false) //there's more data to load
			{
				loading = true; //prevent further ajax loading
				$('.animation_image').show(); //show loading image
				
				//load data from the server using a HTTP POST request
				$.post('/searchdata',{'page_number': track_load,'key':key,'cat_id':cat_id,'lag':lag}, function(data){
									
					$("#results").append(data); //append received data into the element

					//hide loading image
					$('.animation_image').hide(); //hide loading image once data is received
					
					track_load++; //loaded group increment
					loading = false; 
				
				}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
					
					alert(thrownError); //alert with HTTP error
					$('.animation_image').hide(); //hide loading image
					loading = false;
				
				});
				
			}
		}
	});
});
</script>
	@stop